package com.scf.contract.controller;

import com.scf.contract.entity.Borrowing;
import com.scf.contract.entity.Contract;
import com.scf.contract.entity.PageBean;
import com.scf.contract.service.BorrowingService;
import com.scf.uitl.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-12-15:13
 */
@RestController
@RequestMapping("/borrowing")
public class BorrowingController {
    @Resource
    BorrowingService borrowingService;

    @GetMapping("/selectAll")
    public ResponseResult selectAll(Integer pageIndex, Integer pageSize){
        List<Borrowing> borrowings = borrowingService.selectAll(pageIndex,pageSize);
        Integer selectCount = borrowingService.selectCount();
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(200);
        PageBean<Borrowing> pageBean=new PageBean<>();
        pageBean.setBeanList(borrowings);
        pageBean.setPageBegin(pageIndex);
        pageBean.setPageEnd(pageSize);
        pageBean.setTotalRecord(selectCount);

        responseResult.setData(pageBean);
        return responseResult;
    }

    @GetMapping("/selectByname")
    public ResponseResult selectByname(String enterprisename,String code) {
        List<Borrowing> borrowings = borrowingService.selectByname(enterprisename, code);
        ResponseResult resposeResult=new ResponseResult();
        resposeResult.setCode(200);
        resposeResult.setData(borrowings);
        return resposeResult;
    }

    //根据企业id外键查询企业信息
    @GetMapping("/getBorrowingByBoid/{boid}")
    public ResponseResult getBorrowingByBoid(@PathVariable int boid){
        Contract contractByBoid = borrowingService.getBorrowingByBoid(boid);
        ResponseResult responesResult = new ResponseResult();
        responesResult.setCode(200);
        responesResult.setData(contractByBoid);
        return responesResult;
    }




}
